package com.li.utils;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

import org.apache.commons.lang.RandomStringUtils;
 



/**
 * 
 * 工具类
 * @author liandyao
 * @date 2016-1-28 下午02:16:56
 */
public class WxTools {
	
	static Random random = new Random();
	
	static char[] char_random = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };

	static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") ;
	
	/**
	 * 得到当前时间
	 * @return
	 */
	public static String getDateStr(){
		Date date = new Date();
		String s = sdf.format(date);
		return s ;
	}
	  
	public static void main(String[] args) {
		/*int i = 1 ;
		String urlPath = "http://www.ihuopo.com/joke/new_"+i+".html" ; 
		NodeFilter nodeFilter = new HasAttributeFilter("class","content") ; 
		
		try {
			genaraterUrl(urlPath, nodeFilter) ;
		} catch (Exception e) { 
			e.printStackTrace();
		} */
		long time = System.currentTimeMillis()/1000;
		System.out.println(System.currentTimeMillis());
		System.out.println(time);
	}
	
	/**
	 * 随机生成字符串
	 * @return 随机字符串
	 */
	public static String getRandomString(int length){
		String s = RandomStringUtils.random(length,char_random) ; 
		return s  ;
	}

	/**
	 * 得到随机数字
	 * @param num
	 * @return
	 */
	public static int getRandomNumber(int num){
		int n = random.nextInt(num) ;
		return n ;
	}
	
	/**
	 * 判断是否为空
	 * @param obj
	 * @return
	 */
	public static boolean isEmpty(Object obj){
		if(obj==null) return true ;
		if("".equals(obj.toString())) return true ;
		return false ;
	}
	
	/**
	 * 将字符串编码,utf-8格式
	 * @param str
	 * @return
	 */
	public static String encode(String str){
		try {
			 return URLEncoder.encode(str, "utf-8");
		} catch (UnsupportedEncodingException e) { 
			e.printStackTrace();
		}
		return null ;
	}
	
	/**
	 * 得到当前时间戳,1970年到目前的秒数
	 * @return 时间戳
	 */
	public static String getTimeStamp(){
		return System.currentTimeMillis()/1000+"";
	}

}
